package com.zh.note.huawei.onehundred.获取最大软件版本号;

/**
 * @Author: zhanghuan
 * @date: 2023/8/8 11:25
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // String version1 = sc.nextLine();
        // String version2 = sc.nextLine();
        // String version1 = "1.3.11-s2";
        // String version2 = "1.3.11-s13";
        String version1 = "1.05.1";
        String version2 = "1.5.01";
        VersionModel v1 = parseVersion(version1);
        VersionModel v2 = parseVersion(version2);
        int compareValue = v1.compareTo(v2);
        String res = "";
        if (compareValue == 0) {
            res = version1.length() >= version2.length() ? version1 : version2;
        } else {
            res = compareValue > 0 ? version1 : version2;
        }
        System.out.println(res);
    }

    private static VersionModel parseVersion(String version) {

        // 分割
        String[] values = version.split("\\.");
        VersionModel v = new VersionModel();
        v.mainVersion = Integer.parseInt(values[0]);
        v.secondVersion = Integer.parseInt((values[1]));
        if (values.length > 2) {
            String[] str = values[2].split("-");
            v.addVersion = Integer.parseInt(str[0]);
            if (str.length > 1) {
                v.milVersion = str[1];
            }
        }
        return v;
    }

    private static class VersionModel implements Comparable<VersionModel> {
        int mainVersion;
        int secondVersion;
        int addVersion;
        String milVersion = "";

        @Override
        public int compareTo(VersionModel o) {
            if (this.mainVersion != o.mainVersion) {
                return this.mainVersion - o.mainVersion;
            } else if (this.secondVersion != o.secondVersion) {
                return this.secondVersion - o.secondVersion;
            } else if (this.addVersion != o.addVersion) {
                return this.addVersion - o.addVersion;
            } else {
                return this.milVersion.compareTo(o.milVersion);
            }


        }
    }
}
